package com.bobo.service.topicTag;

import com.bobo.dao.topicTag.ITopicTagDao;
import com.bobo.dao.topicTag.TopicTagDaoImpl;
import com.bobo.dto.Page;
import com.bobo.model.Tag;
import com.bobo.model.Topic;
import com.bobo.model.TopicTag;

import java.util.List;

/**
 * Created by bobo on 16-10-28.
 */
public class TopicTagServiceImpl implements ITopicTagService {

    ITopicTagDao topicTagDao = new TopicTagDaoImpl();
    @Override
    public Integer create(TopicTag topicTag) {
        return topicTagDao.create(topicTag);
    }

    @Override
    public boolean delete(TopicTag topicTag) {
        return topicTagDao.delete(topicTag);
    }

    @Override
    public List<Tag> getTags(Integer topicId) {
        return topicTagDao.getTags(topicId);
    }

    @Override
    public Page<Topic> getTopics(Integer tagId,Integer current, Integer pageSize) {
        Page<Topic> page = new Page<>();
        page.setCurrent(current);
        page.setPageSize(pageSize);
        Integer count = topicTagDao.getCount(tagId);
        float pagenum = count.floatValue()/pageSize.floatValue();
        page.setPageNum((int) Math.ceil(pagenum));
        page.setList(topicTagDao.getTopics(tagId,current,pageSize));
        return page;
    }
}
